package com.mfangsoft.zhuangjialong.common.utils;

import java.util.Map;

import com.fasterxml.jackson.databind.ObjectMapper;


public class WeChatApplet {
	
	
	private  static String ACCESS_TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
	
	/**
	 * appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
	 */
	private  static String SESSION_CODE_URL="https://api.weixin.qq.com/sns/jscode2session";
		
	/**
	 * 	二维码图片
	 */
    private  static String	QR_CODE_URL="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN";
    /*
	 * 获取accesstoken
	 */
	public static String getAccessToken(Long user_id,String APPID,String APPSECRET,String app) throws Exception {
			String responseContent = HttpRequest.sendGet("https://api.weixin.qq.com/cgi-bin/token",
					"grant_type=client_credential&appid="+APPID+"&secret="+APPSECRET);
			ObjectMapper objectMapper = new ObjectMapper();
			Map<String,Object> json = (Map) objectMapper.readValue(responseContent, Map.class);
			String accessToken = "";
			if (json != null) {
				if (json.get("access_token") != null) {
					
					CacheUtil.Cache.put(app, json.get("access_token").toString());
					
				}
			}
			return accessToken;
		}

	
}
